package com.cea.papyrustest.uml.deletecommand;

import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Reception;

import com.cea.papyrus.core.commands.UMLElementDeleteCommand;

/**
 * Test class for {@link Reception} creation command
 * @author Remi Schnekenburger
 */
public class ReceptionDeleteCommandTest extends PapyrusCommandTest {

	private static final String NAME = "Reception_0";
	private Class class_;

	/**
	 * Default constructor
	 * @param name the name of the test case
	 */
	public ReceptionDeleteCommandTest(String name) {
		super(name);	
	}

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		class_=(Class)model.getPackagedElement("Class_0");
		if(class_ == null) {
			fail("impossible to find an class_");
		}
		Reception reception = class_.getOwnedReception(NAME, null, null);
		if(reception == null) {
			fail("impossible to find reception");
		}
		papyrusCommand= new UMLElementDeleteCommand(reception, class_);
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		// execute command
		stack.execute(papyrusCommand);
		assertNull("the reception exist!", class_.getOwnedReception(NAME, null, null));

		// undo command
		stack.undo();
		Element clazz=class_.getOwnedReception(NAME, null, null);
		assertNotNull("the reception is re-created",clazz);
		assertTrue("this is not a reception",((clazz)instanceof Reception));
		
		// redo command
		stack.redo();
		assertNull("the reception exist!", class_.getOwnedReception(NAME, null, null));
	}

}
